﻿using UvsChess;
namespace StudentAI.BitBoard
{
    public struct PieceMoving
    {
        public byte DstPosition;
        public bool Moved;
        public ChessColor PieceColor;
        public ChessPieceType PieceType;
        public byte SrcPosition;

        public PieceMoving(ChessColor pieceColor, ChessPieceType pieceType, bool moved,
                           byte srcPosition, byte dstPosition)
        {
            PieceColor = pieceColor;
            PieceType = pieceType;
            SrcPosition = srcPosition;
            DstPosition = dstPosition;
            Moved = moved;
        }

        public PieceMoving(PieceMoving pieceMoving)
        {
            PieceColor = pieceMoving.PieceColor;
            PieceType = pieceMoving.PieceType;
            SrcPosition = pieceMoving.SrcPosition;
            DstPosition = pieceMoving.DstPosition;
            Moved = pieceMoving.Moved;
        }

        public PieceMoving(ChessPieceType pieceType)
        {
            PieceType = pieceType;
            PieceColor = ChessColor.White;
            SrcPosition = 0;
            DstPosition = 0;
            Moved = false;
        }
    }

    public struct PieceTaken
    {
        public bool Moved;
        public ChessColor PieceColor;
        public ChessPieceType PieceType;
        public byte Position;

        public PieceTaken(ChessColor pieceColor, ChessPieceType pieceType, bool moved,
                          byte position)
        {
            PieceColor = pieceColor;
            PieceType = pieceType;
            Position = position;
            Moved = moved;
        }

        public PieceTaken(ChessPieceType pieceType)
        {
            PieceColor = ChessColor.White;
            PieceType = pieceType;
            Position = 0;
            Moved = false;
        }
    }

    public sealed class MoveContent
    {
        public PieceMoving MovingPiece;
        public bool PawnPromoted;
        public PieceTaken TakenPiece;

        public MoveContent()
        {
            MovingPiece = new PieceMoving(ChessPieceType.None);
            TakenPiece = new PieceTaken(ChessPieceType.None);
        }

        public MoveContent(MoveContent moveContent)
        {
            MovingPiece = new PieceMoving(moveContent.MovingPiece);

            TakenPiece = new PieceTaken(moveContent.TakenPiece.PieceColor,
                                        moveContent.TakenPiece.PieceType,
                                        moveContent.TakenPiece.Moved,
                                        moveContent.TakenPiece.Position);
            PawnPromoted = moveContent.PawnPromoted;
        }


        private static byte GetBoardIndex(int col, int row)
        {
            return (byte)(col + (row * 8));
        }
    }
}
